package com.yxjx.duoxue.datamodel;

import java.io.Serializable;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.utils.UIHelper;

/**
 * Wrapper of DMLocationPoint list
 * @author mengmengchen
 *
 */
public class DMLocationPoints implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4044493407230044098L;
	private ArrayList<DMLocationPoint> list = new ArrayList<DMLocationPoint>();
	
	public ArrayList<DMLocationPoint> getList() {
		return list;
	}
	
	public static DMLocationPoints from(JSONArray ja) {
		if (ja == null) {
			return null;
		}
		DMLocationPoints lps = new DMLocationPoints();
		for (int i = 0; i < ja.length(); i++) {
			JSONObject jo;
			try {
				jo = ja.getJSONObject(i);
				DMLocationPoint lp = DMLocationPoint.from(jo.toString());
				lps.getList().add(lp);
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return lps;
	}
	
	@Override
	public String toString() {
		StringBuilder ret = new StringBuilder();
		ret.append("[");
		for (DMLocationPoint point : list) {
			ret.append(point.toString());
		}
		ret.append("]");
		return ret.toString();
	}
}
